package eraserhead.xml.response;

import org.w3c.dom.Node;

import xml.Message;
import client.IMessageHandler;
import eraserhead.boundary.DecisionGUI;
import eraserhead.controller.EndController;
import eraserhead.controller.StatusController;
import eraserhead.xml.XmlNode;

/**
 * Response handler for TurnResponse
 * @author Michael Checca
 */
public class TurnResponse implements IMessageHandler {

	@Override
	public void process(Message response) {
		Node turn = XmlNode.findNode(response.contents, "turnResponse");
		if (turn != null) {
			boolean completed = XmlNode.getAttributeBool(turn, "completed");
			DecisionGUI gui = DecisionGUI.getInstance();
			if (completed)
				new EndController(gui.getModel(), gui).showResults();
			else
				new StatusController(gui.getModel(), gui.getLinesCanvas()).process();
			System.out.println(String.format("TurnResponse received [completed: %s]",
					completed));
		}
	}
}
